﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>表单模版</title>
    <link href="../../Scripts/easyUI145/themes/color.css" rel="stylesheet" />
    <link href="../../Scripts/easyUI145/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="../../Scripts/bootstrap/js/jquery.min.js"></script>
    <script type="text/javascript" src="../../Scripts/bootstrap/js/bootstrap.min.js"></script>
    <script src="../../Scripts/easyUI/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="../../Scripts/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../Scripts/EasyUIUtility.js" type="text/javascript"></script>
    <link href="../../Scripts/SyntaxHighlighter/Styles/shCoreDefault.css" rel="stylesheet"
          type="text/css" />
    <script src="../../Scripts/SyntaxHighlighter/shCore.js" type="text/javascript"></script>
    <script src="../../Scripts/SyntaxHighlighter/shBrushCSharp.js" type="text/javascript"></script>

    <link href="../../Scripts/bootstrap/css/bootstrap.css" rel="stylesheet" />
    <link href="../../Scripts/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../Scripts/config.js" type="text/javascript"></script>
    <script src="../../Comm/Gener.js" type="text/javascript"></script>
    <script src="../../Admin.js"></script>
    <base target="_self" />
    <style type="text/css">
        th, td {
            text-align: left;
        }
    </style>
    <script type="text/javascript">
        var sortNo;
        var retrunUrl;
        $(function () {

            var frmID = GetQueryString("SortNo");

            $("#msg").html("正在加载请稍候...");
            $("#Btn_Imp").hide();

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_Template");
            handler.AddUrlData();
            var data = handler.DoMethodReturnString("Form_Init");
            if (data.indexOf('err@') == 0) {
                alert(data);
                window.history.back();
                return;
            }

            var html = "";
            var data = JSON.parse(data);
            var dirs = data["Dir"];
            var files = data["File"];

            html += "<tr>";
            html += "<th>#</th>";
            html += "<th>模板  - <a href='#' onclick='RetrunToParent()'>上一级</a></th>";
            html += "<th>导入模式</th>";
            html += "<th>表单ID</th>";
            html += "</tr>";

            var idx = 0;
            for (var i = 0; i < dirs.length; i++) {
                var dir = dirs[i];
                idx++;
                html += "<tr>";
                html += "<td class=Idx>  " + idx + " </td>";
                html += "<td><a href=\"javascript:ToParent('" + dir.Path + "')\" ><img src='../../Img/Tree/Dir.gif' />" + dir.FileName + "</a></td>";
                html += "<td>  " + dir.RDT + " </td>";
                html += "</tr>";
            }

            for (var i = 0; i < files.length; i++) {
                var fl = files[i];

                idx++;
                html += "<tr>";
                html += "<td class=Idx>  " + idx + " </td>";
                html += "<td><label><input id=" + fl.FileName + " type='checkbox';  /><img src='../../Img/dot.png' style='width:15px;' />" + fl.FileName + "</label></td>";
                html += "<td>";

                html += "<select id='DDL_" + fl.FileName + "' onchange=changeOption('" + fl.FileName + "')> ";
                html += " <option value=0 >按照模版的表单编号导入,如果该编号已经存在就提示错误. </option> ";
                html += " <option value=1 >按照模版的表单编号导入,如果该编号已经存在就直接覆盖. </option> ";
                html += " <option value=2 >按照模版的表单编号导入,如果该编号已经存在就增加@WebUser.OrgNo(组织编号)导入. </option> ";
                html += " <option value=3 >按照指定的模版ID导入 </option > ";
                html += " </select> ";
                html += " </td > ";
                html += "</td>";
                html += "<td> <input id='TB_" + fl.FileName + "' /> </td>";

                html += "</tr>";
            }

            $("#Table1").html(html);
            $("#msg").html("");
            $("#Btn_Imp").show();
            //$("input").attr("disabled", "disabled");

        });
        function changeOption(id) {
            var optionID = "DDL_" + id;
            var inputID="#TB_"+id;
            var obj = document.getElementById(optionID);
            var sele = obj.options;
            var index = obj.selectedIndex;
            var optionKey = 0;
            if (index > 0) {
                optionKey = sele[index].value
            }
            if (optionKey != "3") {
                $("#TB_").attr("disabled", "disabled");
            }
            else {
                $(inputID).attr("disabled", false);
            }
        }
        //他的上一级目录.
        function ToParent(path) {

            path = path.replace('//', '/');
            retrunUrl = "?SortNo=" + this.GetQueryString("SortNo");
            var url = "?SortNo=" + this.GetQueryString("SortNo") + "&DirName=" + path;
            SetHref(url);
        }
        //返回上一级
        function RetrunToParent() {

            var dirName = GetQueryString("DirName");
            if (dirName == '' || dirName == null) {
                alert('已经是根目录了.');
                return;
            }
            //alert(dirName);
            //var url = "Flow.htm?DirName=" + dirName; //.subStr(0, dirName.length);
            //window.location.href = filterXSS(url);

            window.history.back();//这个没问题，不管怎么点返回的都是上一级
        }
        function Imp() {

            var fls = "";
            var inputArray = $("input[type='checkbox']"); //取到所有的input 并且放到一个数组中
            inputArray.each(//使用数组的循环函数 循环这个input数组
                function () {
                    var input = $(this); //循环中的每一个input元素
                    if (input.is(':checked')) {
                        if (input.attr("id").indexOf(".xml") > 0)//过滤文件，只选xml的
                        {
                            var fileName = input.attr("id");
                            var getModelID = "DDL_" + fileName;
                            var model = document.getElementById(getModelID).value;
                            var getfrmID = "TB_" + fileName;
                            var frmID = document.getElementById(getfrmID).value;
                            fls += fileName + "," + model + "," + frmID + " " + ";"; //查看循环中的每一个input的id
                        }
                    }
                });
            if (fls == "") {
                alert("未选择模板");
                return;
            }

            // alert(fls);

            $("#msg").html("<img src='../../Img/loading.gif' />正在导入请稍候，10分钟左右，请不要关闭");

            //生成要选择的文件.
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_Template");
            handler.AddPara("Files", fls);
            handler.AddPara("SortNo", GetQueryString("SortNo"));
            handler.AddPara("DirName", GetQueryString("DirName"));
            var data = handler.DoMethodReturnString("Form_Step1");
            if (data.indexOf('err@') == 0) {
                $("#msg").html(data);
                return;
            }

            //若选择的多个模板
            if (data.indexOf("EndJSON") == -1) {
                alert(data);
                return;
            }
            //若选择的一个模板，则打开此模板
            var json = cceval('(' + data + ')');

            var html = "<table>";
            html += "<tr>";
            html += "<th>文件</th>";
            html += "<th>结果</th>";
            html += "<th>信息</th>";
            html += "</tr>";

            for (var i = 0; i < json.length; i++) {
                var en = json[i];
                html += "<tr>";
                html += "<th>" + en.Name + "</th>";
                html += "<th>" + en.Result + "</th>";
                html += "<th>" + en.Info + "</th>";
                html += "</tr>";
            }
            html += "/<table>";
            $("#msg").html(html);
        }
    </script>
</head>
<body>

    <div style="float:left;">&nbsp; &nbsp;&nbsp;&nbsp;<img style='margin-bottom:8px;' align='middle' src='../../Img/Event.png' />表单模版</div>
    <div style=" float:right">
        <a href="#" onclick="RetrunToParent()">返回上一级</a>&nbsp; &nbsp;&nbsp;&nbsp;
    </div>

    <table id="Table1" class="table table-hover " style="width: 100%; padding: 2px;text-align:left">
    </table>

    &nbsp;&nbsp;<input type="button" id="Btn_Imp" value="导入模板" onclick='Imp();' />
    <center>
        <div id="msg"></div>
    </center>

</body>
</html>
